package com.controller.lx;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.entity.Confirm;
import com.entity.Detection;
import com.entity.Notelist;
import com.entity.Repairorder;
import com.entity.Process;
import com.entity.PAYRECORD_copy;
import com.entity.BILLRECORD_copy;
import com.entity.DELIVERRECORD_copy;
import com.service.ServiceException;
import com.service.lx.ConfirmService;
import com.service.lx.DetectionService;
import com.service.lx.NotelistService;
import com.service.lx.PAYRECORD_copyService;
import com.service.lx.BILLRECORD_copyService;
import com.service.lx.DELIVERRECORD_copyService;
import com.service.lx.ProcessService;
import com.service.lx.RepairorderService;
import com.entity.ChartVo;
import com.entity.ChartVo2;
import com.utils.Pager;
import com.utils.Result;

@Controller
public class RepairorderController {
	@Autowired
	private RepairorderService repairorderService;
	@Autowired
	private DetectionService detectionService;
	@Autowired
	private ConfirmService confirmService;
	@Autowired
	private ProcessService processService;
	@Autowired
	private NotelistService notelistService;
	@Autowired
	private PAYRECORD_copyService PAYRECORD_copyService;
	@Autowired
	private BILLRECORD_copyService BILLRECORD_copyService;
	@Autowired
	private DELIVERRECORD_copyService DELIVERRECORD_copyService;

	/**
	 * 单条查询
	 * @param field
	 * @param curpage
	 * @param pagesize
	 * @return
	 */
	@PostMapping("/repairorder_oneselect_")
	@ResponseBody
	public Repairorder oneselect(@RequestParam("repairorderId") Long repairorderId){
		return repairorderService.findOne(repairorderId);
	}
	
	/**
	 * 快速查询
	 * @param field
	 * @param curpage
	 * @param pagesize
	 * @return
	 */
	@PostMapping("/repairorder_fastselect_")
	@ResponseBody
	public Page<Repairorder> fastselect(@RequestParam("field") String field, 
			@RequestParam("curpage") Integer curpage, 
			@RequestParam("pagesize") Integer pagesize){
		return repairorderService.findFastAllRepairorders(field, curpage, pagesize);
	}
	
	/**
	 * 逻辑删除
	 * @param Id
	 * @throws ServiceException
	 */
	@DeleteMapping("/repairorder_ifdelete_")
	@ResponseBody
	public Result UpdateIfdelete(Long Id){
		repairorderService.UpdateRepairorderIfdelete(Id);
		return Result.SUCCESS;
	}

	/**
	 * 批量删除 
	 * @param qaIds
	 */
	@PostMapping("/repairorder_delete_arr_")
	@ResponseBody
	public Result deletBatchRoles(@RequestBody JSONArray Ids) {
		repairorderService.deletArrIfDelete(JSONObject.parseArray(Ids.toString(), Long.class));
		return Result.SUCCESS;
	}

	/**
	 * 添加/修改
	 * @param repairorder
	 * @throws ServiceException
	 */
	@PostMapping("/repairorder_addandupdate_")
	@ResponseBody
	public Result addAndUpdate(@RequestBody Repairorder repairorder){
		repairorderService.addAndUpdateRepairorder(repairorder);
		return Result.SUCCESS;
	}
	
	
	/**
	 * 高级查询
	 * @param map
	 * @return 
	 * @throws ServiceException
	 */
	@PostMapping("/repairorder_hightselect_")
	@ResponseBody
	public Pager<Repairorder> hightselect(@RequestBody Map map){
		return repairorderService.findHighAllRepairorders(map);
	}
	
	/**
	 * 选择维修方式
	 * @param repairorder
	 * @throws ServiceException
	 */
	@PostMapping("/repairorder_updatatype_")
	@ResponseBody
	public Result updataType(@RequestParam("repairorderId") Long repairorderId, @RequestParam("repairorderType") BigDecimal repairorderType){
		repairorderService.updataRepairorderType(repairorderId, repairorderType);
		return Result.SUCCESS;
	}

	/**
	 * 修改维修进度
	 * @param repairorder
	 * @throws ServiceException
	 */
	@PostMapping("/repairorder_updataschedule_")
	@ResponseBody
	public Result updataSchedule(@RequestParam("repairorderId") Long repairorderId, @RequestParam("repairorderSchedule") String repairorderSchedule){
		repairorderService.updataRepairorderSchedule(repairorderId, repairorderSchedule);
		return Result.SUCCESS;
	}
	
	/**
	 * 添加/修改检测过程
	 * @param detection
	 * @throws ServiceException
	 */
	@PostMapping("/detection_addandupdate_")
	@ResponseBody
	public Result addAndUpdateDetection_(@RequestBody Detection detection){
		detectionService.addAndUpdateDetection(detection);
		return Result.SUCCESS;
	}

	/**
	 * 添加/修改客户确认
	 * @param confirm
	 * @throws ServiceException
	 */
	@PostMapping("/confirm_addandupdate_")
	@ResponseBody
	public Result addAndUpdateConfirm_(@RequestBody Confirm confirm){
		confirmService.addAndUpdateConfirm(confirm);
		return Result.SUCCESS;
	}

	/**
	 * 添加/修改维修过程
	 * @param process
	 * @throws ServiceException
	 */
	@PostMapping("/process_addandupdate_")
	@ResponseBody
	public Result addAndUpdateProcess(@RequestBody Process process){
		processService.addAndUpdateProcess(process);
		return Result.SUCCESS;
	}

	/**
	 * 添加/修改沟通记录
	 * @param notelist
	 * @throws ServiceException
	 */
	@PostMapping("/notelist_addandupdate_")
	@ResponseBody
	public Result addAndUpdateNotelist(@RequestBody Notelist notelist){
		notelistService.addAndUpdateNotelist(notelist);
		return Result.SUCCESS;
	}
	
	/**
	 * 查询回款单
	 * @param notelist
	 * @throws ServiceException
	 */
	@PostMapping("/notelist_select_")
	@ResponseBody
	public List<Notelist> findNotelist(@RequestParam("repairorderId") Long repairorderId){
		return notelistService.findAllByRepairorderId(repairorderId);
	}
	
	/**
	 * 添加/修改回款单
	 * @param PAYRECORD_copy
	 * @throws ServiceException
	 */
	@PostMapping("/payrecord_addandupdate_")
	@ResponseBody
	public Result addAndUpdatePAYRECORD_copy(@RequestBody PAYRECORD_copy PAYRECORD_copy){
		PAYRECORD_copyService.addAndUpdatePAYRECORD_copy(PAYRECORD_copy);
		return Result.SUCCESS;
	}

	/**
	 * 添加/修改回款单
	 * @param notelist
	 * @throws ServiceException
	 */
	@PostMapping("/payrecord_select_")
	@ResponseBody
	public List<PAYRECORD_copy> findPAYRECORD_copy(@RequestParam("repairorderId") Long repairorderId){
		return PAYRECORD_copyService.findAllByRepairorderId(repairorderId);
	}

	/**
	 * 添加/修改开票记录
	 * @param PAYRECORD_copy
	 * @throws ServiceException
	 */
	@PostMapping("/billrecord_addandupdate_")
	@ResponseBody
	public Result addAndUpdateBILLRECORD_copy(@RequestBody BILLRECORD_copy BILLRECORD_copy){
		BILLRECORD_copyService.addAndUpdateBILLRECORD_copy(BILLRECORD_copy);
		return Result.SUCCESS;
	}

	/**
	 * 添加/修改开票记录
	 * @param notelist
	 * @throws ServiceException
	 */
	@PostMapping("/billrecord_select_")
	@ResponseBody
	public List<BILLRECORD_copy> findBILLRECORD_copy(@RequestParam("repairorderId") Long repairorderId){
		return BILLRECORD_copyService.findAllByRepairorderId(repairorderId);
	}
	
	/**
	 * 添加/修改交付
	 * @param process
	 * @throws ServiceException
	 */
	@PostMapping("/deliverrecord_addandupdate_")
	@ResponseBody
	public Result addAndUpdateDELIVERRECORD_copy(@RequestBody DELIVERRECORD_copy DELIVERRECORD_copy){
		DELIVERRECORD_copyService.addAndUpdateDELIVERRECORD_copy(DELIVERRECORD_copy);
		return Result.SUCCESS;
	}

	/**
	 * 面饼统计图
	 * @throws ServiceException
	 */
	@PostMapping("/chartvo_select_")
	@ResponseBody
	public List<ChartVo> selectchartvo(){
		return repairorderService.selectchartvo();
	}

	/**
	 * 柱状折线统计图
	 * @throws ServiceException
	 */
	@PostMapping("/chartvo2_select_")
	@ResponseBody
	public List<ChartVo2> selectchartvo2(){
		return repairorderService.selectchartvo2();
	}
}
